﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RoardersAgentSim.Map
{
	/// <summary>
	/// Zone definition
	/// </summary>
	public class Zone
	{
		#region private fields
		/// <summary>
		/// The coordinate boundaries of a zone (used to represent visually)
		/// </summary>
		private List<Coords> _boundaries = null;
		/// <summary>
		/// Zone ID
		/// </summary>
		private int _zoneID;
        /// <summary>
        /// node to be used by the decision makers in order calculate the optimal response
        /// </summary>
        public Node CentroidNode;

		#endregion

		#region future implementation fields
		/// <summary>
		/// future implementation
		/// distance of zone to risk area
		/// </summary>
		public double d_h = 0;
		#endregion


		#region properties
		/// <summary>
		/// The coordinate boundaries of a zone (used to represent visually)
		/// </summary>
		public List<Coords> Boundaries { get; set; }
		/// <summary>
		/// zone ID
		/// </summary>
		public int ZoneID
		{
			get
			{
				return _zoneID;
			}
		}
		/// <summary>
		/// Has Shelter flag
		/// </summary>
		public bool HasShelter
		{
			get
			{
				if (this.Nodes == null || !this.Nodes.Any())
					return false;
				return this.Nodes.Any(x => x.HasShelter);
			}
		}
		/// <summary>
		/// The nodes from the zone
		/// </summary>
		public List<Node> Nodes {get;set;}
		#endregion

		#region constructor
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="zoneID"></param>
		public Zone(int zoneID)
		{
			this._zoneID = zoneID;
		}
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="mapping"></param>
		public Zone(CSVUtils.CSVMapping.ZoneMapping mapping)
		{
			this._zoneID = mapping.ZoneID;
			this.d_h = mapping.RiskDistance;
		}
		#endregion

		#region methods
		/// <summary>
		/// Add the coords
		/// </summary>
		/// <param name="coords"></param>
		public void AddCoords(Coords coords)
		{
			if (null == _boundaries)
				_boundaries = new List<Coords>();
			_boundaries.Add(coords);
		}

		#endregion

		public string Description
		{
			get
			{
				return "Zone " + this._zoneID;
			}
		}
	}
	/// <summary>
	/// Zone manager definition
	/// </summary>
	public class ZoneManager : Dictionary<int, Zone> { }
}
